package educar.gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.LayoutManager;
import java.sql.SQLException;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;

import educar.controllers.CorreccionController;
import educar.controllers.DatosController;
import educar.controllers.IController;
import educar.controllers.LoginController;
import educar.controllers.NotaController;
import educar.db.JPA;
import educar.models.Session;

public class DocenteCorreccionView extends JPanel implements IView {
    private JFrame jfWindow;
    JLabel label1;
    JTextField textField1;
    JLabel label2;
    JTextField textField2;
    JButton button1;
    javax.swing.JComboBox jComboBox1;
    String [] nomAct;
    public DocenteCorreccionView() {
        jfWindow = new JFrame();
        Container container = jfWindow.getContentPane();

        setupMainContainer(container);

        jfWindow.pack();
        jfWindow.setVisible(true);
        jfWindow.setResizable(false);
        jfWindow.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }

    private void setupMainContainer(Container container) {
        container.setLayout((LayoutManager) new BoxLayout(jfWindow.getContentPane(), BoxLayout.Y_AXIS));
        ((JComponent) container).setBorder(new EmptyBorder(0, 50,50, 50));

        JLabel lblWelcome = new JLabel(" Seleccione la actividad: ");
        lblWelcome.setAlignmentX(Component.CENTER_ALIGNMENT);
        lblWelcome.setFont(new Font("Serif", Font.BOLD, 16));
        lblWelcome.setBorder(new EmptyBorder(10, 10, 10, 10));
        container.add(lblWelcome);
       
       
        JPA jpa = new JPA();
        try {
        	nomAct =jpa.getConsulta("actividad","nombre","codigo=codigo");
        } 
        catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(nomAct));
        jComboBox1.setName("jComboBox1");
        JPanel usernamePane2 = new JPanel();
        usernamePane2.setLayout(new BoxLayout(usernamePane2, BoxLayout.LINE_AXIS));
        usernamePane2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));                   
        usernamePane2.add(jComboBox1);                   
        container.add(usernamePane2);


        JLabel lblWelcome2 = new JLabel(" Ingrese nota de la actividad: ");
        lblWelcome2.setAlignmentX(Component.CENTER_ALIGNMENT);
        lblWelcome2.setFont(new Font("Serif", Font.BOLD, 16));
        lblWelcome2.setBorder(new EmptyBorder(0, 10, 10, 10));
        container.add(lblWelcome2);
        // Lay out the buttons from left to right.          
        textField1 = new JTextField(20);
        JPanel usernamePane = new JPanel();
        usernamePane.setLayout(new BoxLayout(usernamePane, BoxLayout.LINE_AXIS));
        usernamePane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
        usernamePane.add(Box.createHorizontalGlue());           
        usernamePane.add(Box.createRigidArea(new Dimension(10, 0)));
        usernamePane.add(textField1);
        container.add(usernamePane);

       
       
        //---- button1 ----
               
        JButton baceptar = new JButton("ACEPTAR");
        baceptar.setAlignmentX(Component.RIGHT_ALIGNMENT);
        container.add(baceptar);
       
        LoginListener buttonListener = new LoginListener();
        IController loginController = new NotaController();
        loginController.setView(this);
        buttonListener.associate(baceptar, loginController);

    }
   
    public String getNota() {
        return textField1.getText();
    }
     
     
    public void present(String model) {
    	JOptionPane.showMessageDialog(null, model);
    }

    public String getActividad(){
        return (String) jComboBox1.getSelectedItem();
    }
   
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
           try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
           } 
           catch (Exception ex) {}
           javax.swing.JFrame frame = new javax.swing.JFrame("Datos");
           frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
           frame.getContentPane().add(new DocenteCorreccionView());
           frame.pack();
           frame.setVisible(false);
            
           }
        });
    }
}